package com.zuipin.controller;

import java.math.BigDecimal;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zuipin.enums.CashBackRecordType;
import com.zuipin.framework.annotation.Valid;
import com.zuipin.framework.annotation.Valids;
import com.zuipin.framework.emuns.ErrorCode;
import com.zuipin.framework.exception.CustomException;
import com.zuipin.framework.result.Result;
import com.zuipin.service.ICashBackRecordService;
import com.zuipin.util.RegexUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @ClassName: CashBackRecordController
 * @author wuyicheng
 * @time 2017年3月27日上午8:58:25
 */
@Api(value = "返现变更记录", description = "返现变更记录-wuyicheng")
@RestController
@RequestMapping(value = "/member/cashBackRecord")
public class CashBackRecordController {
	@Resource
	private ICashBackRecordService	cashBackRecordService;
	private static Logger			log	= LoggerFactory.getLogger(CashBackRecordController.class);
	
	//	@RequestMapping(value = "/search", method = RequestMethod.GET)
	//	@ApiOperation(value = "根据id查询返现记录", notes = "根据id查询返现记录")
	//	@Valids({ @Valid(name = "memberId", minValue = 1), @Valid(name = "sysId", minValue = 1),
	//			@Valid(name = "cashBackRecordType") })
	//	@ApiImplicitParams({
	//			@ApiImplicitParam(name = "memberId", value = "会员ID", required = true, dataType = "string", paramType = "query"),
	//			@ApiImplicitParam(name = "sysId", value = "系统ID", required = true, dataType = "string", paramType = "query"),
	//			@ApiImplicitParam(name = "cashBackRecordType", value = "FIRST|SHOPPING|DEDUCTION|SALES_REFUND_RECYCLING|SALES_REFUND类型 首赠 购物赠 抵扣 退货返现回收 退货返现返还", required = false, dataType = "string", paramType = "query"),
	//			@ApiImplicitParam(name = "pageSize", value = "页面大小", required = false, dataType = "string", paramType = "query"), //
	//			@ApiImplicitParam(name = "pageNumber", value = "页码", required = false, dataType = "string", paramType = "query"),//
	//	})
	//	public Result<CashBackRecord> search(
	//			@ApiParam(name = "id", value = "id", required = true) @RequestParam Long id) {
	//		CashBackRecord cashBackRecord = cashBackRecordService.findById(id);
	//		Result<CashBackRecord> result = new Result<CashBackRecord>();
	//		if (cashBackRecord != null) {
	//			result.setData(cashBackRecord);
	//			result.setErrorCode(ErrorCode.SUCCESS);
	//		} else {
	//			result.setData(null);
	//		}
	//		return result;
	//	}
	
	@RequestMapping(value = "/updateCashBackAmount", method = RequestMethod.POST)
	@ApiOperation(value = "余额变更接口-wuyicheng", notes = "余额变更接口-wuyicheng")
	@Valids({ @Valid(name = "memberId", minValue = 1), @Valid(name = "sysId", minValue = 1),
			@Valid(name = "amount", regex = RegexUtils.DOUBLE),
			@Valid(name = "recordType", regex = "FIRST|SHOPPING|DEDUCTION|SALES_REFUND_RECYCLING|SALES_REFUND"), })
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberId", value = "会员ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "sysId", value = "系统ID", required = true, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "createId", value = "创建人ID", required = false, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "updateId", value = "修改人ID", required = false, dataType = "long", paramType = "query"),
			@ApiImplicitParam(name = "amount", value = "修改金额", required = true, dataType = "bigDecimal", paramType = "query"),
			@ApiImplicitParam(name = "recordType", value = "FIRST|SHOPPING|DEDUCTION|SALES_REFUND_RECYCLING|SALES_REFUND类型 首赠 购物赠 抵扣 退货返现回收 退货返现返还", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "remark", value = "备注", required = false, dataType = "string", paramType = "query"), })
	
	public Result<Map<String, Object>> updateCashBackAmount(@RequestParam Long memberId,
			@RequestParam Long sysId, @RequestParam(required = false) Long createId,
			@RequestParam(required = false) Long updateId, @RequestParam BigDecimal amount,
			@RequestParam CashBackRecordType recordType,
			@RequestParam(required = false) String remark) throws CustomException {
		
		Result<Map<String, Object>> result = new Result<>();
		cashBackRecordService.updateCashBackAmount(memberId, sysId, createId, updateId, amount,
				recordType, remark);
		result.setErrorCode(ErrorCode.SUCCESS);
		result.setData(null);
		return result;
	}
	
}
